package com.jsgt.greekfire.ui.trading.otc

import androidx.fragment.app.FragmentTransaction
import com.fhx.core.base.BaseFragment
import com.fhx.core.goToActivity
import com.jsgt.greekfire.LOGIN_STATUS
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.home.entrance.EntranceActivity
import kotlinx.android.synthetic.main.fragment_otc_trading.*

class OTCTradingFragment : BaseFragment() {

    override fun getLayoutId(): Int = R.layout.fragment_otc_trading
    override fun main() {

        val fragmentManager: androidx.fragment.app.FragmentManager = childFragmentManager
        val transaction: FragmentTransaction = fragmentManager.beginTransaction()
        transaction.replace(R.id.fl_fragment_container, OTCTradingBuyFragment())
        transaction.commit()

        radio_group.setOnCheckedChangeListener { group, checkedId ->

            val transaction = fragmentManager.beginTransaction()
            //根据RadioButton不同的Id来选中不同的Fragment。
            if (checkedId == R.id.r_btn_buy) {
                r_btn_buy.textSize = 20f
                r_btn_sell.textSize = 14f
                transaction.replace(R.id.fl_fragment_container, OTCTradingBuyFragment(), "0")
            } else if (checkedId == R.id.r_btn_sell) {
                r_btn_sell.textSize = 20f
                r_btn_buy.textSize = 14f
                transaction.replace(R.id.fl_fragment_container, OTCTradingSellFragment(), "1")
            }
            transaction.commit()
        }
        tvOrder.setOnClickListener { v ->
            if (LOGIN_STATUS) {
                goToActivity<OTCCommissionActivity>()
            } else {
                goToActivity<EntranceActivity>()
            }
        }
    }

}